package wsz.sharding.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import wsz.sharding.entity.Order;

import java.util.List;
import java.util.Map;

/**
 * @author wsz
 * @desc：
 * @date 2022/6/7
 */
@Repository
public interface OrderRepo extends JpaRepository<Order,Long> {

    @Query(nativeQuery = true,value = "select t.* from t_order t where t.year=:year and t.name=:name")
    List<Order> findByParam(@Param("year") int year, @Param("name") String name);

    @Query(nativeQuery = true,value = "select o.*, od.title as title from t_order o left join t_order_detail od on o.id=od.order_id " +
            " where o.year=:year and o.name=:name")
    List<Map> findByParams(@Param("year") int year, @Param("name") String name);
}
